var HashTags = (function() {
	var hashtags = [];
	
	var download = function() {
		console.log("Sciagam popularne hashtagi");
		
		$.post( "http://tomek.ckhost.pl/mirker/wykopTagProxy.php" )
		.done(
			function(html) {
				var $page = $(html);
				
				$page.find("a.newtag").each(
					function(index, object) {
						hashtags[index]={
								url: $(object).attr("href"),
								name: $(object).find("span:not(.number)").text(),
								popularity: $(object).find(".number").text(),
						};
					});
				console.log("Sciaganie popularnych hashtagow zakonczone");
				console.log(hashtags);
			})
		.error(
			function(e) {
				console.log("Blad przy sciaganiu popularnych hashtagow");
				console.log(e);
			});
	};
	
	var getLike = function(q) {
		var matched = [];
		
		$.each(hashtags, function(i, value) {
			if(value.name.indexOf(q) === 0){
				matched.push(value);
			}
		});
		
		return matched;
	};
	
	return {
		download: download,
		get: hashtags,
		getLike: getLike
	};
})();